package cn.shop.merchant.controller.detail;

import cn.dev33.satoken.stp.StpUtil;
import cn.shop.merchant.service.FundDetailService;
import cn.shop.transcation.detail.entity.TransactionRecordQueryReq;
import cn.shop.utils.ApiResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

import static cn.shop.utils.constant.Constant.UID;

/**
 * @author : 李一涵
 * @date : Created in 2021-11-10 10:05
 * @description : 明细controller
 */
@RestController
@RequestMapping("/fund/detail")
public class FundDetailController {

    @Resource
    private FundDetailService detailService;

    /**
     * 获取明细列表
     *
     * @param req 查询条件
     * @return 返回结果
     */
    @GetMapping("/list")
    public ApiResult<Map<String, Object>> list(TransactionRecordQueryReq req) {
        long uid = StpUtil.getSession().getLong(UID);
        if (uid == 0) {
            return ApiResult.fail("请检查登录状态");
        }
        /*if (Utils.isEmpty(req, "current", "size", "orderByTime", "type")) {
            LocalDateTime now = LocalDateTime.now();
            req.setStartTime(now.withHour(0).withMinute(0));
            req.setEndTime(now.withHour(23).withMinute(59));
        }*/
        Map<String, Object> data = detailService.details(uid, req);
        return ApiResult.success(data);
    }

    /**
     * 统计金额
     *
     * @param req 查询条件
     * @return 返回结果
     */
    @GetMapping("/statistics")
    public ApiResult<Map<String, Object>> statistics(TransactionRecordQueryReq req) {
        long uid = StpUtil.getSession().getLong(UID);
        /*if (Utils.isEmpty(req, "current", "size", "orderByTime", "type")) {
            LocalDateTime now = LocalDateTime.now();
            req.setStartTime(now.withHour(0).withMinute(0));
            req.setEndTime(now.withHour(23).withMinute(59));
        }*/
        if (req.getType() == null) {
            req.setType(1);
        }
        return ApiResult.success(detailService.statistics(uid, req));
    }

}
